package com.siae.controller;


import com.siae.pojo.ItemType;
import com.siae.pojo.vo.Result;
import com.siae.service.ItemTypeService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/itemType")
@Tag(name = "ItemTypeController",description = "项目类型的操作")
public class ItemTypeController {
    @Autowired
    private ItemTypeService itemTypeService;

    @GetMapping
    public Result<List<ItemType>> getAllItemTypes(
            @RequestParam(name = "name",defaultValue = "") String name,
            @RequestParam(name = "description",defaultValue = "") String description
    ) {
        return itemTypeService.getAllItemTypes(name, description);
    }
    @GetMapping("/{id}")
    public Result<ItemType> getItemTypeById(@PathVariable("id") Integer id) {
        return itemTypeService.getItemTypeById(id);
    }
    @GetMapping("/name/{name}")
    public Result<ItemType> getItemTypeByName(@PathVariable("name") String name) {
        return itemTypeService.getItemTypeByName(name);
    }
    @PostMapping
    public Result addItemType(@RequestBody ItemType type) {
        return itemTypeService.addItemType(type);
    }
    @PutMapping
    public Result updateItemType(@RequestBody ItemType type) {
        return itemTypeService.updateItemType(type);
    }
    @DeleteMapping("/{id}")
    public Result deleteItemType(@PathVariable("id") Integer id) {
        return itemTypeService.deleteItemType(id);
    }
}
